<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>0);
	if(!empty($_RQ['realname'])){
		$params['realname like']='%'.trim($_RQ['realname']).'%';
		$return['params']['realname']=$_RQ['realname'];
	}
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	$fields=array('id','title','salecate','status','applytime','realname');
    $orderby='id desc';
	$total='';
	$return['list']=pdo_getslice('jy_chengedu_jigou',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	foreach($return['list'] as &$v){
		$v['applytime']=date('Y/m/d H:i:s',$v['applytime']);

	}
	$return['status']=array('0'=>'待审核','1'=>'已审核','2'=>'已驳回');
	$return['status2']=array('0'=>array('id'=>0,'title'=>'待审核'),'1'=>array('id'=>1,'title'=>'已审核'),'2'=>array('id'=>2,'title'=>'已驳回'));
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'入驻申请'),	
		),
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'title','title'=>'机构名称','type'=>'string'),
			array('name'=>'salecate','title'=>'主营项目','type'=>'string'),								
			array('name'=>'realname','title'=>'联系人','type'=>'string'),
			array('name'=>'applytime','title'=>'申请时间','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),			
		),'action'=>array(
			array('type'=>'modal','op'=>'look','title'=>'机构信息'),
			array('type'=>'modal','op'=>'check','title'=>'审核'),
		)),
		'search'=>array(			
			array('name'=>'realname','width'=>15,'title'=>'联系人','type'=>'string'),
			array('name'=>'status','width'=>15,'title'=>'状态','type'=>'select','options'=>'status2'),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='check'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_chengedu_jigou',array('id'=>$id));
	}else{
		exi('无效id','error','list');
	}
    $return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'入驻申请',
		'tabs'=>array(
			array('op'=>'list','title'=>'入驻申请'),
		),
		'edit'=>array(
			array('name'=>'title','title'=>'机构名称','type'=>'copy'),
			array('name'=>'status','title'=>'审核状态','type'=>'radio','options'=>'status'),
			array('name'=>'reason','title'=>'驳回原因','type'=>'text','show'=>array('status'=>2)),			
			)
	);
	$return['status']=array('0'=>'待审核','1'=>'审核通过','2'=>'驳回');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$post=get_postdata();
	if($post['id']){
		pdo_update('jy_chengedu_jigou',array('status'=>$post['status'],'reason'=>$post['reason']),array('id'=>$post['id']));
		exi('操作成功','','list');
	}
	exi('操作失败，ID为空','','list');
}
if($_RQ['op']=='look'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_chengedu_jigou',array('id'=>$id));
		$item['lat_lng']=json_decode($item['lat_lng']);
		$item['onlinetime']=json_decode($item['onlinetime'],true);
	}else{
		$item=array();
	}
	$item['codeimg']=$item['codeimg']?json_decode($item['codeimg'],true):array();
	$item['upass']='';
    $return['item']=$item;
	$htmls=array( 
		'type'=>'look',
		'desc'=>'机构详情',
		'look'=>array(
			array('name'=>'title','title'=>'机构名称','type'=>'string'),
			array('name'=>'logo','title'=>'机构logo','type'=>'image'),
			array('type'=>'image','title'=>'店招','name'=>'topimg'),
			array('name'=>'isbrand','title'=>'属于品牌？','type'=>'switch'),
			array('name'=>'salecate','title'=>'主营项目','type'=>'string'),	
			array('name'=>'cateid','title'=>'机构分类','type'=>'select','options'=>'cate','option_title'=>'catename'),
			array('name'=>'realname','title'=>'联系人','type'=>'string'),
			array('name'=>'mobile','title'=>'电话','type'=>'string'),
			array('name'=>'desc','title'=>'机构简介','type'=>'text'),
			array('type'=>'text','title'=>'机构公告','name'=>'remark'),
			array('name'=>'address','title'=>'机构地址','type'=>'string'),	
			array('name'=>'tel','title'=>'机构电话','type'=>'string'),
			array('name'=>'groupid','title'=>'机构组','type'=>'select','options'=>'group','option_title'=>'groupname'),	
			array('name'=>'codeimg','title'=>'营业执照/许可证','type'=>'images'),
			array('name'=>'content','title'=>'机构详情','type'=>'richtext'),
		)
	);
	$return['cate']=pdo_getall('jy_chengedu_category',array('uniacid'=>$_SESSION['uniacid']),array('id','catename'));
	$return['group']=pdo_getall('jy_chengedu_group',array('uniacid'=>$_SESSION['uniacid']),array('id','groupname'));
	$return['htmls']=$htmls;
	exi($return);
}
?>